package com.koron.css2.systemManage.servlet;

import com.koron.css2.ApplicationConfig;
import com.koron.css2.ServerInterface;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.systemManage.bean.query.BatchOrgOperationQueryBean;
import com.koron.css2.systemManage.service.ServiceFactory;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.swan.bean.MessageBean;

/**
 * 批量添加
 */
public class BatchAddOrgOperation implements ServerInterface {

    private static Logger log = LoggerFactory.getLogger(AddOrgOperation.class);

    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        MessageBean<BatchOrgOperationQueryBean> msg = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "添加成功", BatchOrgOperationQueryBean.class);
        try {
            BatchOrgOperationQueryBean bean = JsonUtils.objectToPojo(req.getData(), BatchOrgOperationQueryBean.class);
            if(bean.getOrgCodeList() == null || bean.getOrgCodeList().size() == 0) {
                msg.setCode(Constant.MESSAGE_INT_FAIL);
                msg.setDescription("组织不能为空");
                return msg;
            }
            if(bean.getOperationCodeList() == null || bean.getOperationCodeList().size() == 0) {
                msg.setCode(Constant.MESSAGE_INT_FAIL);
                msg.setDescription("操作不能为空");
                return msg;
            }
            ServiceFactory.getOperationService().addOrgOperation(ApplicationConfig.getAppCustomerAppid(), bean.getOrgCodeList(), bean.getOperationCodeList());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("新增菜单出错：" + e);
            msg.setCode(Constant.MESSAGE_INT_FAIL);
            msg.setDescription(e.getMessage());
        }
        return msg;
    }
}
